App.controller("generalizeDataCtr",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	var params = JSON.parse($stateParams.params);
	console.log("路由参数：",params);
	
	$scope.search_1 = {};		//搜索参数
	$scope.search_2 = {};		//搜索参数
	$scope.search_3 = {};		//搜索参数
	$scope.search_4 = {};		//搜索参数
	$scope.search_5 = {};		//搜索参数
	$scope.product = {};        //查看详情数据【订单推广】
	$scope.record = {};         //沟通记录
	
	$scope.operate_1_show = true;			//操作——客户列表（显示）
	
	
	$scope.shopName_1_hidden = false;		//预约商户（隐藏）
	$scope.shopName_2_hidden = false;		//预约商户（隐藏）
	$scope.shopName_3_hidden = false;		//所属商户（隐藏）
	$scope.shopName_5_hidden = false;		//所属商户（隐藏）
	$scope.operation = true;               //操作的显示隐藏
	
	var guitListData = [];    //获取分配人员的列表数据
	var guitIds = '';         //批量分配时获取选中的分配人员的id
	
	if(params.guiderState=="正常"){
		$scope.operate_1_show = false;
	}
	
	//【顾客推广】
	var clientGeneralize = [
   		             {
		            	 value: "",
		 				text: "请选择"
		             },
		             {
		            	 value: "1",
		 				text: "已联系"
		             },
		             {
		            	 value: "2",
		 				text: "已进店"
		             },
		             {
		            	 value: "3",
		 				text: "已购卡"
		             },
		             {
		            	 value: "4",
		 				text: "已经订单"
		             },
		             {
		            	 value: "5",
		 				text: "已活动"
		             },
		             {
		            	 value: "6",
		 				text: "已物流"
		             },	
		             {
		            	 value: "7",
		 				text: "已安装"
		             },
		             {
		            	 value: "8",
		 				text: "售后中"
		             },
		             {
		            	 value: "9",
		 				text: "已关闭"
		             },
		             
        ];
	var pointData = [
		             {
		            	 value: "",
		 				text: "请选择"
		             },
		             {
		            	 value: "1",
		 				text: "分享积分"
		             },
		             {
		            	 value: "2",
		 				text: "订单积分"
		             },
		             {
		            	 value: "3",
		 				text: "客户积分"
		             },
		             {
		            	 value: "4",
		 				text: "登录积分"
		             },
		             {
		            	 value: "5",
		 				text: "沟通积分"
		             }
        ];
	var orderStates = [
		             	{
			            	value: "",
			 				text: "请选择"
			             },
			             {
			            	 value: "1",
			            	 text: "物流"
			             },
			             {
			            	 value: "2",
			            	 text: "安装"
			             },
			             {
			            	 value: "3",
			            	text: "售后"
			             },
			             {
			            	 value: "4",
			            	text: "关闭"
			             }    
		        ];
	var gifNum =1;         //产品信息记录    有几条
	var userformData = [
			             {
			            	 value: "",
			 				text: "请选择"
			             },
			             {
			            	 value: "1",
			 				text: "公司分配"
			             },
			             {
			            	 value: "2",
			 				text: "邀请注册"
			             } 
		             ];
	
	var alertModel = {};	//alert模态框
	
	if(userInfo.user_level==0){	//开发者
		
	}else if(userInfo.user_level==3){	//三级用户
		$scope.storeshow = true;     //操作隐藏
	}else if(userInfo.user_level==2){	//二级用户
		$scope.storeshow = true;     //操作隐藏
		$scope.operation = false;
	}else if(userInfo.user_level==1){	//一级用户
		$scope.shopName_1_hidden = true;		
		$scope.shopName_2_hidden = true;		
		$scope.shopName_3_hidden = true;		
		$scope.shopName_5_hidden = true;
	}
	//付款方式
 	$("#paymentMethod").kendoDropDownList({
	    dataTextField: "name",
	    dataValueField: "name",
		dataSource: [
					{
						id:"",
						name:"请选择"
					},
					{
						
						id:"",
						name:"现金"
					},
		            {
						id:"",
						name:"pos机"
	            	},
	            	{
	            		id:"",
	            		name:"微信"
	            	},
	            	{
	            		id:"",
	            		name:"支付宝"
	            	}
	      ]
 	});
	//用户渠道
	$("#user_channel").kendoDropDownList({
        dataTextField: "text",
	    dataValueField: "value",
	    dataSource: userformData,
      	change: function(e) {
      	},
	});
	//订单状态
	$("#order_state").kendoDropDownList({
		dataTextField: "text",
	    dataValueField: "value",
		dataSource: orderStates
	});
	//积分类型
	$("#integral_type").kendoDropDownList({
		dataTextField: "text",
	    dataValueField: "value",
		dataSource:pointData ,
        change: function(e) {
		    var value = parseInt(this.value());
		    values = value;
		}
	});
	//选择菜单
	$scope.chooseMenu = function(type){
		for(var i=1;i<=5;i++){
			if(i==type){
				$("#menu_"+i).addClass("active");
				$("#container_"+i).show();
			}else{
				$("#menu_"+i).removeClass("active");
				$("#container_"+i).hide();
			}
		}
	}
	
	//客户推广
	$scope.gridOptions_1 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/related/customer",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									exshopper_id:params.guideId,  //导购id
									name:$scope.search.customer_name,   //客户姓名
									phone:$scope.search.phones,  //联系方式
									property:$('#user_channel').val()   //用户渠道   1代表公司分配，2表示推广注册
									
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					},
					model: {
				          id: "id",
				          fields: {
				        	  id:{ editable: false},
				        	  name: { editable: false},
				        	  phone: { editable: false},
				        	  property: { editable: false},
				        	  create_time: { editable: false},
				          }
				    }
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: true,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "name",         
						title : "客户姓名",     
						width : "100px"
					},
					{
						field : "phone",         
						title : "联系方式",     
						width : "100px"
					},
					{
						field : "property",         
						title : "用户渠道",     
						width : "100px",
						values:userformData
					},
					{
						field : "",         
						title : "注册时间",     
						width : "100px",
						template:function(e){
							 return	publicService.switchTime(e.create_time,'dateTime');
						}
					},
					{
						field : "",         
						title : "沟通记录",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	
					    	html += '<div class="operation" ng-click="lookUser_generalize('+e.id+')">查看</div>';
					    	
					    	return html;
					    }
					},
					{
						field : "operation",         
						title : "操作",     
						width : "100px",
						hidden: $scope.operation,
						template: function(e){
							if(params.guiderState=="关闭"){
								return '<div class="canEdit">分配店员</div>';
							}else{
								return '<div>分配店员</div>';
							}
					    },					 
					    editor: function (container, options,e) {
					    	if(params.guiderState=="关闭"){
					    		$('<input data-bind="value:' + options.field + '"/>')
						        .appendTo(container)
						        .kendoDropDownList({
						           dataTextField: "name",
								   dataValueField: "id",  //id
						           dataSource: guitListData,
						 	      change: function(e) {
						 	        var value = this.value();
						 	       $scope.editState(value,options.model.id);
						 	      }
						        });
							}else{
								$('<span>分配店员</span>')
						        .appendTo(container);
							}	
						},	
					}
			]
	};
	
	//订单推广
	$scope.gridOptions_2 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/related/order",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									exshopper_id:params.guideId,  //导购id
									order_code:$scope.search.order_number,  //订单编号
									order_state:$('#order_state').val(),//订单状态
									create_time:$('#order_down_time').val(), //下单时间
									product_model:$scope.search.product_type //产品型号
									
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "order_code",         
						title : "订单号",     
						width : "100px"
					},
					{
						field : "",         
						title : "下单日期",     
						width : "100px",
						template:function(e){
							 return	publicService.switchTime(e.create_time,'dateTime');
						}
					},
					{
						field : "order_state",         
						title : "订单状态",     
						width : "100px",
						values:orderStates
					},
					{
						field : "product_model",         
						title : "产品型号",     
						width : "100px"
					},
					{
						field : "customerName",         
						title : "买家",     
						width : "100px"
					},
					{
						field : "userManager_name",         
						title : "商户名称",     
						width : "100px",
						hidden: $scope.shopName_2_hidden
					},
					{
						field : "order_price",         
						title : "实收现金",     
						width : "100px"
					},
					{
						field : "",         
						title : "操作",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	
					    	html += '<div class="operation" ng-click="showDetails('+e.id+',0)">查看详情</div>';
					    	
					    	return html;
					    },
					}
			]
	};
	
	//积分明细
	$scope.gridOptions_3 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/related/integral",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									exshopper_id:params.guideId,   //导购id
									type_index:$('#integral_type').val(),  //积分类型
									create_time:$('#generalize_time').val() //推广积分
									
									
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<span class='row-number subTitle'></span>"
					},
					{
						field : "",         
						title : "积分类型",     
						width : "100px",
						template:function(e){
							return "【"+e.type_name+"】"+e.title;
						}
					},
					{
						field : "point",         
						title : "积分额度",     
						width : "100px"
					},
					{
						field : "",         
						title : "推广日期",     
						width : "100px",
						template:function(e){
							 return	publicService.switchTime(e.create_time,'dateTime');
						}
					}
			]
	};
	
	//客户报备
	$scope.gridOptions_4 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/related/customerReport",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									exshopper_id:params.guideId, //导购
									phone:$scope.search.relationPhone,  //电话
									create_time:$('#report_data').val()   // 报备时间
										
									
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<span class='row-number subTitle'></span>"
					},
					{
						field : "customer_name",         
						title : "客户姓名",     
						width : "100px"
					},
					{
						field : "phone",         
						title : "联系方式",     
						width : "100px"
					},
					{
						field : "",         
						title : "报备日期",     
						width : "100px",
						template:function(e){
							 return	publicService.switchTime(e.create_time,'dateTime');
						}
					}
			]
	};
	
	//表格对象
	$scope.gridOptions_5 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/selectGiftPage",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "multiple"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "",         
						title : "被邀请人昵称",     
						width : "100px"
					},
					{
						field : "",         
						title : "联系方式",     
						width : "100px"
					},
					{
						field : "",         
						title : "注册日期",     
						width : "100px"
					},
					{
						field : "",         
						title : "所属导购",     
						width : "100px"
					},
					{
						field : "",         
						title : "所属专卖店",     
						width : "100px",
						hidden: $scope.shopName_5_hidden
					},
			]
	};
	
	//查询
	$scope.search = function(type){
		$scope["grid_"+type].dataSource.page(1);
//		$scope.orderWindow.center().open();   //打开弹框
	}
	
	//全选，取消
	$scope.chooseAll = function(className,flag){
		publicService.chooseAllByClassName(className,flag);
	}
	
	//筛选导出
	$scope.downloadBySearch = function(){
		
	}
	
	//选中导出
	$scope.downloadByChoose = function(){
		
	}
	//-----------------------------客户推广--------------------------------------
	//查看
	$scope.lookUser_generalize = function(id){
		$scope.record = {};
		$('#aboutChat div').html('');  //清空数据
		/*$scope.designWindow.center().open();   //打开弹框*/		
		var postDatas = {
				exshopper_id:params.guideId,
				customer_id:id
		}
		$http({
			   url: path+'/server/related/customer/selectCommunicate',
			   method: 'POST',
			   data:angular.toJson(postDatas)
		}).success(function(data){ 
			if(data.code==0){  //成功
				console.log(data);
				var resultData1 = data.result;
				if(!resultData1){
					alert("暂无沟通记录")
					return;
				}
				
				if(resultData1.gender ==1){
					$scope.record.gender ="男" ;  //性别
				}else if(resultData1.gender ==2){
					$scope.record.gender ="女" ;  //性别
				}
				$scope.record.state =clientGeneralize[resultData1.lastState].text;  //状态
				$scope.record.age = resultData1.age;  //年龄
				$scope.record.timer = publicService.switchTime(resultData1.update_time,'dateTime') ;  //沟通时间
				
				$scope.record.install_area = resultData1.erection_space;  //预约安装面积
				$scope.record.house_area = resultData1.floor_space;  //预约房屋面积
				if(resultData1.installation_time_start ==null&&resultData1.installation_time_end ==null){
					$scope.record.install_timer = "暂未定";
				}else{
					$scope.record.install_timer =publicService.switchTime( resultData1.installation_time_start,'dateTime')+'--'+publicService.switchTime(resultData1.installation_time_end,'dateTime');  //预约安装时间
				}

				$scope.record.pattern = resultData1.install_style;  //预约安装模式
				console.log(resultData1.customerUserManagerBasicList);
				var html = '';
				$.each(resultData1.customerUserManagerBasicList,function(index,obj){
					var indexs =parseInt(index)+1 ;
					
					html+='<div class="acommunication">'
							+'<div  class="col-sm-4 control-label">'+ publicService.switchTime(obj.communicate_time,'dateTime')+'</div>'
							+'<div  class="col-sm-4 control-label">'+obj.communicate_content+'</div>'
							+'<div  class="col-sm-4 control-label">'+clientGeneralize[obj.state].text+'</div>'
						+'</div>';
//					$(html).appendTo($('#aboutChat'));
					
				});
				$('#aboutChat').html($(html));
				$scope.designWindow.center().open();
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
	};
	//分配其他导购的导购人员
	$scope.getGuitList = function(){
		var getData = {
			user_manager_id:params.guideId
		};
		$http({
			   url: path+"/server/selectAllUserManager",
			   method: 'POST',
			   data: angular.toJson(getData)
		}).success(function(data){
			if(data.code==0){  //成功
				guitListData = data.result;
				$scope.allotGiut(guitListData);
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			console.log(data);   
		})
	};
	//分配人员的实例化
	$scope.allotGiut = function(data){
		$("#batchAllot").kendoDropDownList({
			dataTextField: "name",
		    dataValueField: "id",
			dataSource: data,
	        change: function(e) {
	 	        var value = this.value();
	 	       guitIds = value;
	 	      }
		});
	};
	//分配人员编辑状态
	$scope.editState = function(id,stateId){
		var postData = {
				user_manager_id: id,     //修改后的导购id
				customer_id: stateId    //客户id
		};
		
		$http({
			   url: path+"/server/updateCustomerUserManager",
			   method: 'POST',
			   data: angular.toJson(postData)
		}).success(function(data){
			if(data.code==0){  //成功
				alert('操作成功！');
				$scope.search(1);
			}else if(data.code==1){  //失败
				alert("接口错误！请联系管理员！");
			}
		}).error(function(data){
			console.log(data);   
		})
	};	
	//批量分配
	$scope.batchAllocation = function(){
		var inputLength = publicService.getChooseValueByClassName('recordClass').length;
		if(inputLength>0){
			$scope.getGitWindow.center().open();   //打开弹框  
		}else{
			alert("请先勾选消费者！");
		};
	};
	$scope.bathGiutDatas = function(){
		var selectGuitId = $("#batchAllot").data("kendoDropDownList").value();//支付方式
		var inputLength = publicService.getChooseValueByClassName('recordClass');
		var checkArr = {};
		checkArr.customer_ids = inputLength;   //消费者id
		checkArr.user_manager_id = selectGuitId;  //导购id
		$http({
			   url: path+'/server/updateCustomerUserManagerBath',
			   method: 'POST',
			   data: angular.toJson(checkArr), 
		}).success(function(data){ 
			if(data.code==0){  //成功
				$scope.getGitWindow.center().close();   //打开弹框  
				$scope.search(1);
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
	}
	//-----------------------------订单推广--------------------------------------
	//显示详情(0 表示详情，1表示用编辑(暂无))
	$scope.showDetails = function(id,num){
		$http({
			   url: path+"/server/selectOrderDetail",
			   method: 'POST',
			   data:id
		}).success(function(data){
			
			if(data.code==0){  //成功
				var datails = data.result;
				$scope.booking_detail.center().open();   //打开弹框  
				$('#box_product .newProduct').remove();   //清空产品信息
				console.log("显示详情页  ",datails);
				if(datails){   //有详情信息
					$scope.product.orderId = datails.orderId; //订单id
					$scope.product.orderCode = datails.orderCode;   //订单编号
					$scope.product.activityName = datails.activityName;   //活动名称
					$scope.product.activityCode = datails.activityCode;   //活动编号
					$scope.product.createTime = datails.createTime;   //下单时间
					$scope.product.orderState = datails.orderState;   //订单状态	
					$scope.product.sellerName = datails.sellerName;   //专属顾问
					$scope.product.sellerPhone = datails.sellerPhone;   //专属顾问电话
					$scope.product.customerName = datails.customerName;   //客户姓名
					$scope.product.customerPhone = datails.customerPhone;   //联系电话
					
					//【收货信息】
					$scope.product.consignee = datails.consignee;   //收货人
					$scope.product.consigneePhone = datails.consigneePhone;   //联系电话
					$scope.product.consigneeAddress = datails.consigneeAddress;   //收货地址
					
					for(var i=1;i<datails.productInfoList.length;i++){
						$scope.addgif();
					}
					
					//【产品信息】
					$timeout(function(){
						var detailNum = 1;
						$.each(datails.productInfoList,function(index,objs){
							var box_products = $('#box_product .product_infos_show:eq('+parseInt(detailNum-1)+')');
							$(box_products).children("input:nth(0)").val(objs.productModel);  //产品型号
							$(box_products).children("input:nth(1)").val(objs.price);  //产品单价
							$(box_products).children("input:nth(2)").val(objs.num);  //购买数量
							$(box_products).children("input:nth(3)").val(objs.totalPrice);  //产品总价
							detailNum++;
						});
				    }, 100);

					//【支付信息】
					if(datails.depositPrice){
						$scope.product.depositPrice = datails.depositPrice;//定金
					}else{
						$scope.product.depositPrice =0;//定金
					}
					
					$scope.product.realPayPrice = datails.realPayPrice;//实收金额
					$scope.product.isUseActivityCard = datails.isUseActivityCard;//是否使用卡券
					
					$("#paymentMethod").data("kendoDropDownList").value(datails.payStatus)//支付方式
					console.log(datails.activityDetail);
					var activity_name_num = 1;
					$.each(datails.activityDetail,function(index,objs){
						if(activity_name_num== 1){
							$scope.activity_name1 = objs.name+'次数';//抽奖的名字
							$scope.activity_num1 = objs.num;//抽奖次数
							activity_name_num++;
							$('#activity1').val(objs.itemId);  
						}else{
							$scope.activity_name2 = objs.name+'次数';//砸金蛋名字
							$scope.activity_num2 = objs.num;//砸金蛋次数
							$('#activity2').val(objs.itemId);  
						}

					});
					
					$scope.product.prizes = datails.prizes;//奖品
					$scope.product.prize = datails.prize;//满赠礼品				
					
					//【备注、说明】
					$scope.product.explain = datails.explain;   //说明
					$scope.product.remarks = datails.remarks;   //备注
					countNumsData =datails.activityNumRule; //抽奖次数的计算
					fullPresent = datails.activityPresentRule;  //满赠规则
					
					if(num == 0){  //查看详情
						$("input").attr("disabled","true");//让所有的input变为只读
						$('#box_product .add_reduce').hide();
						$('#productSubmitButton').hide();
						$("#paymentMethod").data("kendoDropDownList").readonly(true);
						$("textarea").attr("disabled","true");
					}else if(num == 1){
						$("input").removeAttr("disabled");//让所有的input变为只读
//						$('#box_product .add_reduce').show();
						$('#productSubmitButton').show();
						$("#paymentMethod").data("kendoDropDownList").readonly(false);
//						$("textarea").attr("disabled","false");
						$("textarea").removeAttr("disabled");
					}
				}else{
					alert("暂无详情信息！");
				}
				
				
			}else if(data.code==1){  //失败
				alert(data.message);
			}
		}).error(function(data){
			alert(data);   
		})
	};	
	//新增产品
	$scope.addgif = function(){
		if(gifNum<=50){
			gifNum = ++gifNum;    //每次点击增加一个
			var html1 =	'<div class="product_infos_show productId'+gifNum+' newProduct">'
							+'<img class="add_reduce" src="../../images/icon/reduce.png" ng-click="removergif('+gifNum+')">'
							+'<p class="boxInfo1">产品型号：</p>'
							+'<input class="k-textbox boxInfo2" />'
							+'<p class="boxInfo1">产品单价：</p>'
							+'<input  class="k-textbox boxInfo2" ng-blur="productCount()"/>'
							+'<p class="boxInfo1">购买数量：</p>'
							+'<input  class="k-textbox boxInfo2"  ng-blur="productCount()"/>'
							+'<p class="boxInfo1">产品总价：</p>'
							+'<input class="k-textbox boxInfo2" />'
						+'</div>';
			html1 = $compile(html1)($scope);  
			$(html1).appendTo($('#box_product'));
		}else{
			alert("最多可以增加50个礼品！");
		}
	};

	//删除增加的礼品
	$scope.removergif = function(id){
		$('#box_product .productId'+id+'').remove();
		gifNum = --gifNum;    //每次点击增加一个
		
	};
	//计算产品的总价
	$scope.productCount = function(index){
		var tag =angular.element(event.target).parent().children('.boxInfo2');
		if(tag[1].value&&tag[2].value){
			tag[3].value = tag[1].value * tag[2].value;
			console.log(tag[3].value);
		}

	}
	//计算砸金蛋次数、抽奖次数
	$scope.calculateMoney = function(){
		var depositPrice = parseInt($scope.product.depositPrice);  //预付定金
		var giftNum = [];   //满奖的礼物
		if(countNumsData){
			var activity_name_num = 1;
			$.each(countNumsData,function(index,objs){
				if(activity_name_num == 1){
					var motion = depositPrice/(objs.useMoney);  //第一个的
					$scope.activity_name1 = objs.name+'次数';//抽奖的名字
					$scope.activity_num1 = motion;//抽奖次数
					activity_name_num++;
				}else{
					var motion = depositPrice/(objs.useMoney);  //第二个的	
					$scope.activity_name2 = objs.name+'次数';//砸金蛋名字
					$scope.activity_num2 = motion;//砸金蛋次数
				}
			});
		}
		$.each(fullPresent,function(index,objs){
			
			if(depositPrice - objs.useMoney >=0){
				giftNum.push(objs.gift);
			}
			
		});
		$scope.product.prize = giftNum.join("-");   //满减礼物的展示
	};
	//-----------------------------积分明细--------------------------------------
	
	//-----------------------------客户报备--------------------------------------
	
	
	
	

	publicService.initDate("order_down_time");   //下单时间【订单推广】
	publicService.initDate("generalize_time");   //推广日期【积分明细】
	publicService.initDate("report_data");   //推广日期【客户报备】
//	publicService.initOrderState("order_state");  //订单状态 【订单推广】

	
	
	$scope.chooseMenu(1);
	$scope.getGuitList();//分配其他导购的导购人员
	
	
	
});

